/**
 * 封装C++11 的线程 
 */
#pragma once 
#include "noncopyable.h"
#include <atomic>
#include <functional>
#include <string>
#include <thread>
#include <memory>
#include <atomic>
namespace TinyRPC{

enum ThreadState{
    Init,
    Running,
    Join,
    Detach
};

class Thread : public Noncopyable{
public:
    using ThreadFunc = std::function<void()> ;

    Thread(ThreadFunc task, const std::string& name="");
    void start();
    void join();
    void detach();

    pid_t getTid();

    std::string getName();

private:
    void setDefaultName();
private:
    ThreadFunc m_task;
    pid_t m_tid;
    std::string m_name;
    std::unique_ptr<std::thread> m_thread;
    ThreadState m_state;

    // 线程创建的总数
    static std::atomic<int> NumOfThreads;  //线程总数
};


}
